I'm somewhat new to grails (not groovy though) and I'm working on a sample CRUD application. The issue I'm trying to solve is how to set a property on a bean based on a radio button before I update it in the database. Is the Form Helper http://www.grails.org/plugin/form-helper plugin the way to go? Will the bean have its value set regardless of if the button is actually clicked by the user or if it is left at its default value?
thanks,
Jeff
Have you tried setting the name of the radio buttons to the bean property name and include the radio buttons in your form or remoteForm submission?
Related
I've created a bean to search an sql table. This bean produces an arraylist that is displayed in a rich:dateTable. For each row in this table, there is a column that is a link to another page that specifies which record in the table is to be displayed, e.g.:
<h:link id="profile_last_name" value="#{record.string}" outcome="#{search.action()}">
<f:param name="user_id" value="#{record.getInteger('user_id')}"/>
</h:link>
The search bean is passed a navigation outcome, e.g. "staffEditUser" that creates a URL like:
http://localhost:8080/staff/edit/user.xhtml?user_id=98
I'd like to change the search bean so that if there is only one row in the search result, it immediately goes to the edit page. I know how to do the redirect if I knew the destination page name but I don't; all that I know inside the search bean is the navigation outcome. Is there some way to access the navigation rules from inside the bean?
Alternatively, and this seems very kludgy to me, could I simply add parameters to a redirect in the xhtml file that would be processed by the jsf navigation? If so, how?
Thanks very much for any help.
You can redirect the JSF page from within your managed bean method with
FacesContext.getCurrentInstance().getExternalContext().redirect("url");
As I understand you. You should check inside your ManagedBean database read method if the returned results have the size of none and then redirect to the edit page of this record.
I have a primitive view: a form containing a validatable text input component and a command button. The input value is pointing to a session-scoped backing bean.
I open the page, enter an invalid value and submit the form: after the postback, a validation error is appearing and the input component is displaying the submitted value which did not pass validation. The model value in my session-scoped bean is left intact, as expected.
Ok, now I open another tab in the browser and open the same page. To my surprise, the input component is displaying the submitted value from the first tab. I've been supposing the view state to be new at another GET request and the plain model value from my session-scoped bean to be shown instead.
If I use a view-scoped bean instead of a session-scoped one the model value is being rendered for the input component in the second tab, not the submitted value from the first tab.
Is the submitted value not the part of the view state and kept somehow along with the model? Or is its scope tuned up in some smart way depending on the referenced bean's scope?
Sorry in advance if this question is stupid but I will be very grateful for removing my misunderstanding.
Trying to develop a composite component using jsf2.0 (Mojarra) which should render command buttons dynamically based on the list from the bean. The button action and immediate attribute are working fine.Trying to add the action Listener attribute whereas the action Listener should not work for the buttons whose immediate attribute value is true.Could anyone please suggest me how to achieve?
You can put two mutually exclusive command button into your component, one of them has actionListener and only renders when the immediate attribute is false, where as the other should only be rendered when the immediate attribute is true and it doesn't have actionListener.
<h:commandButton value="buttonWithoutActionListener"
rendered="#{cc.attrs.immediate}"/>
<h:commandButton value="buttonWithActionListener"
rendered="#{!cc.attrs.immediate}"
actionListener="#{cc.yourListener}"/>
I am new to JSF. I have 3 cascading SelectOneMenu i.e Countries, States and Cities. The functionlity is when country is selected corressponding states are populated and when state is selected cities are populated.
I am using a4j:support tag for implementing it. My managed bean is in request scope and is spring managed beans.
I have written ActionListener for CountriesChanged(), StatesChanged() and CitiesChanged().
In my application when one selects countries, action event is fired and states are populated.
However, when one changes states, it throws "Validation Error : Value is not valid"
It would be helpful if somebody guides me proper direction.
You need to prepare exactly the same list of states during the form submit request as it was during the form display request. JSF will namely re-validate the submitted value against the list of available items. In case of a request scoped bean, you have to prepare it in the bean's (post)constructor. Another way is to put the bean in the new JSF 2.0 view scope so that the bean don't get recreated whenever you submit the form against the same view.
I am using JSF 2.0/CDI and PrimeFaces 2.2.1 for a number of CRUD forms that let the user view or update the attributes of an existing entity by clicking on a link in a datatable, where the identifier of the entity is passed to the CRUD form as a View Parameter. I display the entity's ID (often just an integer) on the CRUD form in a PrimeFaces InputText field with the readonly attribute set to true (since I can't let them change it), so the user knows which entity they're editing. The backing bean of the CRUD form is RequestScoped, which works fine except when validation fails. In that case, the value of the View Parameter is lost, so a 0 is displayed in the entity ID field on validation failure.
I am able to maintain the actual entity ID in a hidden field so it's available to update the database once validation succeeds, but it's rather maddening that I've not been able to find a way to maintain the value in a visible field of some sort after a validation failure. Ideally the InputText field would retain its functionality as an inputted and validated field even with its readonly (or disabled) attribute set to true, which would let me forgo the hidden field entirely. But it doesn't appear that I can make it work that way. Any suggestions besides making the backing bean ConversationScoped, which I'd prefer to avoid?
Actually, after stating what I'm looking for a little differently in a Google search I found a novel suggestion at the link below that seems to work cleanly. Instead of making the entity ID field readonly or disabled, I leave it enabled but blur it as soon as it receives focus. I'm able to get rid of the hidden field, the user can't change the value and it survives a validation failure.
<p:inputText id="entid" value="#{RequestBean.entityID}" onfocus="blur();" />
http://www.codingforums.com/archive/index.php/t-1738.html