JSF listeners in selectOneMenu - list

I have a selectOneMenu item with some products. Some of them are unavailable so after you click on it the button "Add" should be disabled and some message should appear that "Sorry the product you chose is currently unavailable". I have no idea how to achieve that. Tried listeners, ajax and still nothing.
This is one of many versions of my JSF Page:
<h:form>
<h:selectOneMenu value="#{productBean.productName}">
<f:selectItems id ="other" value="#{productBean.other}" var="other" itemValue="#{ordersBean.productName}" itemLabel="#{other.name}" />
<f:ajax listener="#{productBean.valueChanged}" />
</h:selectOneMenu>
<h:commandButton value ="Dodaj do zamówienia" rendered="#{productBean.available}"/>
<h:outputLabel id="orderSummary"/>
</h:form>
Beans are rather standard. I just need a clue how to do that and probably I will be able to do it myself.
Thanks in advance.

Here's one of the ways:
In your AJAX listener you could check if a product is available and set up bean field accordingly, or add a message for a component.
Introduce a component in your view that'll hold the message to the user, for example with the #{bean.available ? '' : 'Sorry, out of stock'} value, or enclose it within a <h:panelGroup> and let that component have a rendered attribute, or attach <h:message>/<h:messages> somewhere in your view.
Specify id of the message holder to be rendered within render attribute of <f:ajax> tag.

Related

Pass id or class name to points(ticks) inside canvas

I am using react-chartjs-2 to render charts and on clicking the active point it gets redirected to some other page.
<Line
id={'chartid'}
data={data}
options={options}
getElementAtEvent={dataset => {
// redirects to some other page
}}
/>
Sample chart
We are doing automation testing and need to check if click is working or not.
Is there any option to add id/class to active elements inside the rendered canvas. Can anyone help?
AFAIK every element has got datasetIndex and index properties related to the drawn dataset.
Emitting the click event on the canvas (a specific point) you could check that dataset index and index are what you are expecting

Sitecore WFFM Form not working when inserted as a web control

I created a form which works if I add it as control to Presentation --> Details. What I need to do on another page is inserting the same web form as a web control like this:
<wffm:FormRender FormID="{72857A3A-B6C5-48C0-995B-FA053C82870F}" runat="server" />
The form is shown on the page, but the validations report not filled fields, although they are filled.
Am I missing something?
There you go. This is what you need to do.
<wffm:FormRender FormID="{72857A3A-B6C5-48C0-995B-FA053C82870F}" FormTemplate="/sitecore modules/web/Web Forms for Marketers/Control/SitecoreSimpleFormAscx.ascx" runat="server" />

CFWheels: Display form errors on redirectto instead of renderpage

I have a form which I am validating using CFWheels model validation and form helpers.
My code for index() Action/View in controller:
public function index()
{
title = "Home";
forms = model("forms");
allforms = model("forms").findAll(order="id ASC");
}
#startFormTag(controller="form", action="init_form")#
<select class="form-control">
<option value="">Please select Form</option>
<cfloop query="allforms">
<option value="#allforms.id#">#allforms.name#</option>
</cfloop>
</select>
<input type="text" name="forms[name]" value="#forms.name#">
#errorMessageOn(objectName="forms", property="name")#
<button type="submit">Submit</button>
#endFormTag()#
This form is submitted to init_form() action and the code is :
public function init_form()
{
title = "Home";
forms = get_forms(params.forms);
if(isPost())
{
if(forms.hasErrors())
{
// don't want to retype allforms here ! but index page needs it
allforms = model(tables.forms).findAll(order="id ASC");
renderPage(action="index");
//redirectTo(action="index");
}
}
}
As you can see from the above code I am validating the value of form field and if any errors it is send to the original index page. My problem is that since I am rendering page, I also have to retype the other variables that page need such as "allforms" in this case for the drop down.
Is there a way not to type such variables? And if instead of renderPage() I use redirectTo(), then the errors don't show? Why is that?
Just to be clear, I want to send/redirect the page to original form and display error messages but I don't want to type other variables that are required to render that page? Is there are way.
Please let me know if you need more clarification.
This may seem a little off topic, but my guess is that this is an issue with the form being rendered using one controller (new) and processed using another (create) or in the case of updating, render using edit handle form using update.
I would argue, IMHO, etc... that the way that cfWheels routes are done leaves some room for improvement. You see in many of the various framework's routing components you can designate a different controller function for POST than your would use for GET. With cfWheels, all calls are handled based on the url, so a GET and a POST would be handled by the same controller if you use the same url (like when a form action is left blank).
This is the interaction as cfwheels does it:
While it is possible to change the way it does it, the documentation and tutorials you'll find seem to prefer this way of doing it.
TL; DR;
The workaround that is available, is to have the form be render (GET:new,edit) and processing (POST:create,update) handled by the same controller function (route). Within the function...
check if the user submitted using POST
if it is POST, run a private function (i.e. handle_create()) that handles the form
within the handle_create() function you can set up all your error checking and create the errors
if the function has no errors, create (or update) the model and optionally redirect to a success page
otherwise return an object/array of errors
make the result error object/array available to view
handle the form creation
In the view, if the errors are present, show them in the form or up top somewhere. Make sure that the form action either points to self or is empty. Giving the submit button a name and value can also help in determining whether a form was submitted.
This "pattern" works pretty well without sessions.
Otherwise you can use the Flash, as that is what it was created for, but you do need to have Sessions working. their use is described here: http://docs.cfwheels.org/docs/using-the-flash and here:http://docs.cfwheels.org/v1.4/docs/flashmessages
but it really is as easy as adding this to your controller
flashInsert(error="This is an error message.");
and this to your view
<cfif flashKeyExists("error")>
<p class="errorMessage">
#flash("error")#
</p>
</cfif>

openerp7.0 the attribute attrs of button goes the field cannot be found

I want to realize the button on the current logon were not visible:
<group attrs="{'invisible': [('shenqr.user_id','=', uid)]}">
<button string="prove" name="fjj_action_prove" states="wait_prove"
groups="qingjia.group_assistant_depmanager" />
</group>
but it says the field shenqr.user_id cannot be found
while i use like this:
<field name="domain">[('shenqr.user_id','<>',uid)]</field>
it works.
what is the problems
You could not get it works in attrs, because it does not support. To make such things, you need to add fields on the current model
In attrs you can only pass OpenERP basic domain.
The domain is parsed by the Web client. That force you to have all fields used in domain in the view event if not shown, they must be invisible fields.
The domain value must be static.
attrs="{'readonly': [('my_filed_must_be_in_view', '=', 'static_value')]}"
You can not use complex function, or server related code the scope is limited to the view.
Domain
Normaly when you add a domain on a field using view definition you can use any kind of standard domain condition.
[('invoice.partner_id.name', '=', True)]
But you have to consider your self outside of system. It means you can only do domain that will work trough an XMLRPC call.
In the domain value you can use any static value or any field value. Once again if you want to use a field that is not shown as a value, it must be present in view even if invisible.
I do not think you can use context in domain value like in ir.action domain but I will not be categoric.
Regards

TFS 'when' and 'required' rules does not set the field to required

I have a custom field (fixedInVersion), the field is required when state = 'Closed'.
I also have a custom control for the field (combo with sorting, because the default sorting of TFS control is ascending).
When the work Item state is Closed, I display in my control Required but the user can still save the work item without getting error.
Does anyone knows what is the problem?
If I remove the text Required the item cannot be saved, but the only indication for the user is that the combo is yellow (no text Required is displayed).
The "When" Required value, did you use it? see the following example:
<FieldDefinition refname="fixedInVersion" name="fixedInVersion" type="String">
<WHEN field="System.State" value="Closed">
<REQUIRED />
</WHEN>
</FieldDefinition>