required=true page parameter not working? - seam

I've just discovered a required attribute in the pages.xml:
<page view-id="/competition-list.xhtml">
<param name="season" value="#{seasonHome.id}" converterId="javax.faces.Integer" validator="#{startYearValidator}" required="true" />
</page>
However, when manually deleting the parameter from the URL nothing happens, that is the query is still executed (though it returns no elements), which I didn't expect.
What am I doing wrong?

Page parameter validation affects the execution of page action. When validation fails, page action is not executed and a FacesMessage is added.
Maybe you want to add a page action to load competitions so that the query is not executed when the season parameter is not valid:
<page view-id="/competition-list.xhtml"
action="#{seasonHome.loadCompetitions}">
<param name="season"
value="#{seasonHome.id}"
converterId="javax.faces.Integer"
validator="#{startYearValidator}"
required="true" />
</page>

Related

How to deal with "The ID '...' is already used by another control when conditionally removing controls?

I have a custom control that currently conditionally renders content:
<me:CustomControl>
<switch>
<if "expression is true">
<textbox id="Name" />
</if>
<if "expression is true">
...
</if>
<else>
<textbox id="Name" />
</else>
</switch>
</me:CustomControl>
My example above makes no logical sense, but gets straight to the point. The <if> tag is evaluated by overriding the GetChildControlType function. The <textbox> inside is evaluated in the <if>'s control builder.
What I want to do is completely remove the control from the collection, or even better yet, prevent child controls of <if> from being added to the collection to begin with. If I try to remove them OnInit, I still get the error "The ID 'Name' is already used by another control."
I can't evaluate them in the:
Public Overrides Function GetChildControlType(ByVal tagName... ) As Type
Because I need to perform logic on all the if's and else's within it.
Maybe there's a better way?
Update
I get a compilation error even if I break this thing down to bare bones if there are more than one controls with the same ID, even though overriding CreateChildControls. not sure if I can get around this at all.

Alfresco Share - Dynamic rendering of fields in a form

My question is more or less in the title, I added a new data type in my data model.
<type name="moi:montype">
<title>titre type</title>
<parent>cm:content</parent>
<mandatory-aspects>
<aspect>moi:monaspect</aspect>
</mandatory-aspects>
</type>
This one uses a new aspect in which I added a new field
<aspect name="moi:monaspect">
<title>titre aspect</title>
<properties>
<property name="moi:monchamp">
<type>d:text</type>
<mandatory>false</mandatory>
</property>
...
</properties>
</aspect>
I then displayed this new field in a Share form by editing the file share-config-custom.xml.
<config evaluator="node-type" condition="moi:montype">
<forms>
<form>
<field-visibility>
<show id="moi:monchamp"/>
...
</field-visibility>
<appearance>
<field id="moi:monchamp" label="Champ texte" />
...
</appearance>
</form>
</forms>
</config>
Till then, I could test my changes and the new field displays well.
But I would like to go further, and condition for example the display of the field depending on the logged in user's group.
If the logged in user is part of the "priviledged group", then the field is displayed, otherwise it will not, or only in read only mode.
Do you think we can do this ? And how ?
I looked at documentation, but can't find my happiness.
I don't ask for the full solution, but for tips to follow.
Thank you for your help.
Every field has a component renderer. These are implemented using FreeMarker. Most of the time, as in your case, you are relying on the default component renderer. In addition to the options mentioned by Matjaz, another option would be to point the field at a custom renderer. The renderer could inspect the user's group membership and the group required for this field (maybe passed in as an argument, for example), and then decide whether or not to show itself.
There are a few ways to do this.
The easiest way is to make a webscript which returns html for a form field based on if a current logged in user is in your target group. Then add a form control which is only javascript making an ajax call to the webscript and and appending results to your container div which is specified in your form control (ftl).
The second approach you could use is to extend "org.alfresco.repo.forms.processor.AbstractFilter" and implement the functionality in Java. You could probably implement after generate and remove the form field if current logged in user is not in a target group.
Hope this helps a bit... :)
There is no easy way to do this as alfresco does not allow you to set rights on node properties.
Every field has control template, you could define your own. in your template you would define how this property is rendered depending of user type.
<config evaluator="node-type" condition="cm:content">
<forms>
<form>
<appearance>
<field id="cm:title">
<control template="/org/alfresco/components/form/controls/yourOwnFtl.ftl" />
</field>
</appearance>
</form>
</forms>
</config>
Another approach is to write your own share config form evaluator (like node-type ...)
This could check for node type and user permission role/group
let you write one config for each setup (per user group/role)
...
NB! this will one work for forms, so is purely a cosmetical setup, alfresco interface and CIFS etc. will not support this setup.

Webflow: Manipulating a conversation scoped object in an action

I'm new to Webflow and am having an issue: I have some form objects which delegate to an underlying conversation scoped object (and thus modifying it when the form is bound on post). However, subsequent actions don't see the modifications - it appears when binding, the form is manipulating a different instance of the object than the one in the conversation scope.
Here is one of the view states that has this issue:
<view-state id="groupAccount" model="groupAccountForm" >
<on-entry>
<evaluate expression="enrollmentAction.createApplication()"
result="conversationScope.application" />
<evaluate expression="enrollmentAction.createGroupAccountForm(fapplication)"
result="viewScope.groupAccountForm" />
</on-entry>
<transition on="cancel" to="finish"></transition>
<transition on="continue" to="employee">
<!-- <evaluate
expression="groupAccountForm.getApplication()" result="conversationScope.application" /> -->
<evaluate
expression="enrollmentAction.save(application)" />
</transition>
</view-state>
On entry, I create my conversation scoped object and then create the form bean passing it. When the page is submitted, the binding works just fine however, the application passed to enrollmentAction.save(..) doesn't have the values from the page. The commented out line above it solves the issue but there's got to be a better way of handling this.
This is running on Jetty 6.1, it's a prototype so no authenticated user.

dotnetnuke dnnLEFTMENU doesn't show up in custom skin

I'm working on my own dotNetNuke skin, and I'm trying to add a dnnLEFTNAV to my skin. However, I'm having trouble getting it to show up in the skin itself. This is what my invocation in my .html skin looks like:
<object id="dnnLEFTMENU" codetype="dotnetnuke/server" codebase="LEFTMENU">
<param name="Width" value="165px" />
<param name="ShowOnlyCurrent" value="RootItem" />
<param name="MaxLevel" value="2" />
<param name="EnableEmbeddedSkins" value="false" />
<param name="Skin" value="MinimalExtropy" />
</object>
When the skin is uploaded, the .html is converted to .ascx, and the incovation ends up looking like this:
<dnn:LEFTMENU runat="server" id="dnnLEFTMENU" Width="165px" ShowOnlyCurrent="RootItem" MaxLevel="2" EnableEmbeddedSkins="false" Skin="MinimalExtropy" />
There's also a header:
<%# Register TagPrefix="dnn" TagName="LEFTMENU" Src="~/Admin/Skins/LeftMenu.ascx" %>
However, when I look at the completed page, there is absolutely nothing where the LEFTNAV should be.
What makes this even odder is that I essentially pulled this code verbatim out of the Minimal Entropy skin, and a test page with the Minimal Entropy skin has the nav showing up as expected.
Any ideas?
Oh boy is my face red. The page I was using the LEFTMENU on had no child menus...I was expecting it to include same-level items or at least the shell of an empty navigation but apparently not.
PBKAC

How to enforce jsf to create new instance of bean instead of throwing NullPointerException?

I'm almost sure that I do something wrong and thus the question's title is a bit incorrect.
I have a form with several fields for creating a new User-objects (fields like login, password, birthday etc). And I have 2 buttons - Cancel and Create. I didn't finish Create yet :) , but when I press Cancel I see NullPointerException. Here is simplified code:
<f:view>
<h:form>
<h:panelGroup layout="block">
<h:inputText id="add_login" value="#{userSupport.user.login}"/>
<h:inputSecret id="add_password" value="#{userSupport.user.password}"/>
<h:inputText id="add_name" value="#{userSupport.user.name}"/>
<h:inputText id="add_surname" value="#{userSupport.user.surname}"/>
<h:commandButton value="Cancel" action="cancel"/>
</h:panelGroup>
</h:form>
</f:view>
UserSupport class has field user with getter and setter and some other methods. It's a Spring bean with Session scope.
When I press cancel, I see NPE because jsf tries to save values from inputs in user-object, but user-object is null.
What is the correct way of doing this?
on your cancel button set immediate="true"
This will skip all the "unwanted" phases.
The same problem, however, will arise with your "create" button, and you shouldn't use immediate there.
Better initialize the user property - either in constructor, or using the #PostConstruct annotation on a method, which does the initialization actions.

Resources