Thanks again! Without support from forums and mailing lists
I would probably have condemned JSF by now and would be doing
ASP.NET - just kidding :-)

It may be the same problem I complained about here:
   
http://www.nabble.com/-Trinidad--Aaaaaargg---validateDoubleRange-broken-on-JSF-RI-1.2-tf4351379.html

I tried using myfaces 1.2 instead of RI, but on tomcat 6 that
does not work either
   https://issues.apache.org/jira/browse/MYFACES-1682

It is mentioned that using facelets rather than jsp helps, maybe
I'll try that with my little test app.
Note that I previously had to use a patched version of facelets
with trinidad because of this problem:
   https://facelets.dev.java.net/issues/show_bug.cgi?id=239

Hope you can understand my frustration a little.

Back to the validation issue:
Does client side validation work for you, when you use sub-forms?
(Because if that's simply not working yet on subforms with
default="true", then the complete failure for me might very
well be the same bug I mentioned above with RI 1.2 and trinidad.)

Anyway thanks a lot for your explanations! It is good to know that
it's only a bug (in my setup or trinidad or jsf RI), rather than
a general problem.

Will research it some more.


Vadim Dmitriev wrote:
Stephen Friedrich wrote:
Thanks a lot Vadim - the layout is looking nice now.
Somehow I never noticed the showRequired attribute.
I additionally needed to add a message component plus some layout.
Just in case: if you added tr:message to display messages of "<tr:selectOneChoice id="projectLeadSelect" inline then be aware that
panelLabelAndMessage does it automatically.
However validation still does not work. The problem in your
suggestion is that submitting the form using the outer "Save"
button does not validate anything at all.

The description of "default" attribute for subform is really vague
in the tag docs: It controls wether the subform "assumes it has been 
submitted". Huh? I don't really care what the subform assumes or how
it feels or wether it has a bad day ;-)
What exactly is the effect of "default" be? How does it behave when multiple subforms have default set?

Is it possible in any way for the outer form when submitted to cause
validation for all subforms?

Actually "default" attribute does exactly what you have suggested: if
outer form was submitted from it's event (not bubbled from some of it's
child subform), then all "default" subforms will also be processed.
If subform is not default, then it will not be processed after
applyRequestValues phase.
However, it is how I understand it's behavior. I too find subform
description a little unclear.

As for you example:
1. if you click "-->" then event's source subform will be processed
(selectOneChoice is validated) and all parent's form input components
(if any). "project name" subform is ignored. In general - all other
subforms (weather they are default or not) will be ignored.
2. if you click "Save" button, then all form's components will be
processed, and all it's default subforms (both inputs will be validated
for "required" constraint).

Strange, that it don't work for you. I tested it on Trinidad
1.0.2/MyFaces 1.1.5 and everything was working as you asked.

Anybody?
Help?
Please?





Hi.
You can try something like that (removed all EL's to test it locally):

        <tr:form defaultCommand="saveButton">
            <tr:panelFormLayout>

                <tr:subform default="true">
                    <tr:panelLabelAndMessage    for="projectLeadSelect"
styleClass="inputLabel_10"    label="Project Lead"
                                                showRequired="true" >
                        <tr:panelHorizontalLayout>
                            <tr:selectOneChoice id="projectLeadSelect"
                                                simple="true"
                                                required="true"
                                                unselectedLabel="" >
                            </tr:selectOneChoice>
                            <tr:commandLink action="employee" text="-->" />
                        </tr:panelHorizontalLayout>
                    </tr:panelLabelAndMessage>
                </tr:subform>
                <tr:subform default="true">
                    <tr:inputText label="Project Name " required="true" />
                </tr:subform>

                <tr:commandButton id="saveButton" text="Save"
action="saved" />
            </tr:panelFormLayout>
        </tr:form>
Note, that if selectOne's unselectedLabel will be other than empty
string and it will be the only option in select element, then
selectOneChoice will be validated only on server side.
Assume both inputs are empty. In that case on form submit via button
only inputText will be marked as invalid, and only when it will pass
validation - selectOneChoice will be processed (server-side).

As for "required" mark placement, I guess one of the options is to
implement your own renderer for panelFormLayout.

Hope it helps.


Stephen Friedrich wrote:
I have to implement lots of forms in the same style:
Wherever another entity is shown there is also a link that goes to
another page
containing another form with the details of that entity. Did not look
that
difficult when I first saw the sketches, but I have a hard time
getting it to
work correctly.

See screenshot for my first cut at this and the code of the page at
the bottom
of this message.

First of all I haven't been able to get validation work as desired:

- When the link "-->" is clicked
  * the dropdown must be validated (can't navigate to a person's
details if
    no person is selected).
  * The project name field must not be validated (project isn't saved
anyway)
- When "Save" button is clicked both project lead dropdown and project
name
  field must be validated.

I tried various combinations of using subforms and/or immediate
without success.
All I ever got was either validation of project name not working when
I select
save or else working even when I select "-->" (or other errors like the
employee's id not transfered to the employee bean before navigation to
the
employee details).

Any suggestions?

Also the layout is of course not that nice:

- How do I get the dropdown and text field aligned, with the required
asterisk
showing before the "Project Lead" label? (Well, actually required
asterisk
should be _after_ the label, but that's not that important right now).
I guesss I could make the dropdown simple and add a message tag
myself, but that
complicates layout even further. Also how to get the required asterisk
shown at
the label in that case.

I spent lots of hours on this and can't see a solution anywhere close,
so any
help or suggestions are highly appreciated!


--------------------------------------------------------------------------------
-
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="trh" uri="http://myfaces.apache.org/trinidad/html"; %>
<%@ taglib prefix="tr" uri="http://myfaces.apache.org/trinidad"; %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"; %>

<f:view>
    <trh:html>
        <trh:head/>
        <trh:body>
            <tr:form defaultCommand="saveButton">
                <tr:panelFormLayout>

                    <tr:panelLabelAndMessage
styleClass="inputLabel_10" label="Project Lead">
                        <tr:panelHorizontalLayout>
                            <tr:selectOneChoice required="true"
value="#{project.selectedEmployeeId}">
                                <f:selectItems
value="#{project.allEmployees}"/>
                            </tr:selectOneChoice>
                            <tr:commandLink action="employee" text="-->">
                                <tr:setActionListener
from="#{project.selectedEmployeeId}" to="#{employee.id}"/>
                            </tr:commandLink>
                        </tr:panelHorizontalLayout>
                    </tr:panelLabelAndMessage>

                    <tr:inputText label="Project Name "
required="true" value="#{project.projectName}"/>

                    <tr:commandButton id="saveButton" text="Save"
action="saved"/>
                </tr:panelFormLayout>
            </tr:form>
        </trh:body>
    </trh:html>
</f:view>

Reply via email to