Primefaces dataTable edit cells next to header - jsf-2

I'm trying to draw an assistance table with primefaces and I'm facing some troubles with <p:dataTable>.
The scenario
The table should be as follows:
-----------------------------------------------------------------------------------------
| | Date and assistance (1) | |
| Name (1) |-------------------------------------------------------| % |
| |(4)| | | | | | | | | | | | | | |
-----------------------------------------------------------------------------------------
|Lastname, firstname (2) |(3)| | | | | | | | | | | | | | (5) |
-----------------------------------------------------------------------------------------
|...[more rows]... |
-----------------------------------------------------------------------------------------
In (1) I have the titles (not editable of course). In (2) I have the person data which is brought from the DB and is not editable also.
In (3) I have an editable cell with a dropdown list for the possible values [P, A, L] (Present, Absent, Late).
In (4) I need to insert the date of the assistance (not necessarily the current date).
Finally, in (5) I have the current assistance percentage, which is a calculated field.
The problem
I'm not being able to to make (4) editable, e.g. with a <p:inputMask pattern="dd/MM"> tag
Failed Attempt
I tried with the grouping property of of <p:dataTable>, something like:
<!-- Assist class has the properties char value, Person person and Date date -->
<p:dataTable var="assist" value="#{assistBean.lstAssist}"
editable="true" editMode="cell">
<p:columnGroup type="header">
<!-- The "headers" properly said -->
<p:row>
<p:column rowspan="2" headerText="Name"/>
<p:column colspan="#{someBean.colAmount}" rowspan="1" headerText="Date and assistance"/>
</p:row>
<!-- The editable dates -->
<p:row>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{assist.date}">
<f:convertDateTime pattern="dd/MM"/>
</h:outputText>
</f:facet>
<f:facet name="input">
<p:inputMask value="#{assist.date}" style="width:96%" mask="99/99"/>
</f:facet>
</p:cellEditor>
</p:column>
</p:row>
</p:columnGroup>
<p:column>...
... The rest of the table
</p:column>
</p:dataTable>
This doesn't work because every field in the <p:columnGroup type="header"> doesn't renders the <input>.
I also tried some other combinations but I can't mix the headers with the editable cells.
Any help or guide will be appreciated, I'm also open to other options. Thanks in advance

I don't know if you still need a solution but you can do what you need puting this on the editable header (of course p:inplace is optional you can remove it, f:facet is what you need):
<p:column>
<f:facet name="header">
<p:inplace>
<p:inputText value="#{bean.yourvalue}"/>
</p:inplace>
</f:facet>
</p:column>

Related

How to select a certain number of descendants of a node using xpath?

say i had the following xml:
<a>
<b>
<c>
<d />
<e />
</c>
</b>
<g>
<b>
<h />
<f />
</b>
</g>
if i want to select all the descendants of the node 'b' i can use the following xpath query:
//b//*
or using axes :
//b/descendant::*
But i want to select only 4 descendants of the node 'b', does anyone know how to do it please?
PS : i'm using xpath 1.0
//c/descendant::*[position() <= 4]
It's settled! I just should use the parentheses like this :
(//b/descendant::*)[position()<=4]
because without them, the [position() <= 4] part will be applied to the descendant element's position in its parent rather than its position in the result node set.

How do I filter a ng-repeat by a boolean attribute in Angular.Dart?

Each space is an object with a boolean attribute called open, and I'm putting them into two lists. In this case, I have two of them, one is true and one is false. When the list renders at all, both items are in the open list. Here's what I've tried:
ng-repeat="space in ctrl.manager.spaces | filter:open"
ng-repeat="space in ctrl.manager.spaces | filter:!open"
and
ng-repeat="space in ctrl.manager.spaces | filter:open:true"
ng-repeat="space in ctrl.manager.spaces | filter:open:false"
and
ng-repeat="space in ctrl.manager.spaces | filter:{'open':true}"
ng-repeat="space in ctrl.manager.spaces | filter:{'open':false}"
{{space.open}} confirms that one is true and one is false.
The correct way to apply this filter is
ng-repeat="item in items | filter: {open: 'true'}
ng-repeat="item in items | filter: {open: '!true'}
(put the 'true' in quotes)

Primefaces Input for Money Input (exactly 2 digits after floating point)

I need a PrimeFaces input component, to get/set an amount of cash, that means a Decimal with 2 digits after the floating point.
I tried using inputMask, like
<p:inputMask value="#{moneyBean.amount}" mask="999.99"/>
But I can't find some way to set a mask that accepts:
1 or more arithmetic values before floating point
Optionally, a floating point "."
0 to 2 arithmetic values after the floating point
For Example, some valid inputs would be:
1234.56
1234.5
2.8
120
120.00
Any ideas to get this input in an efficient way?
A regular expression was the best way I've found so far
<p:inputText id="numInput" value="#{val.value}" required="true"
label="#{val.title}" validatorMessage="Not valid Number">
<p:ajax event="change" process="#form" update=":edit_main" />
<f:validateRegex pattern="^[-+]?[0-9]*\.?[0-9]{1,2}+$" />
</p:inputText>
<p:message for="numInput" />
you can use Client Side Validation tag visit link
http://www.primefaces.org/showcase/ui/csvEvent.jsf
There are so may example that can help you.
i think your problem will be resolved by these two tag
<f:validateDoubleRange minimum="5.5" maximum="8.5" />
and
<p:clientValidator />
tell if not work.
Now i got exactly what you want. you want only two digit after "."
The Prime Faces extensions are provide such type of checks.
Go throw the link
http://www.primefaces.org/showcase-ext/sections/inputNumber/advanceUsage.jsf
it will sure help you.

Dynamic 'matches' statement in XSLT

I'm trying to create an xslt function that dynamically 'matches' for an element. In the function, I will pass two parameters - item()* and a comma delimited string. I tokenize the comma delimited string in a <xsl:for-each> select statement and then do the following:
select="concat('$di:meta[matches(#domain,''', current(), ''')][1]')"
Instead of the select statement 'executing' the xquery, it is just returning the string.
How can I get it to execute the xquery?
Thanks in advance!
The problem is that you are wrapping too much of the expression in the concat() function. When that evaluates, it returns a string that would be the XPath expression, rather than evaluating the XPath expression that uses the dynamic string for the REGEX match expression.
You want to use:
<xsl:value-of select="$di:meta[matches(#domain
,concat('.*('
,current()
,').*')
,'i')][1]" />
Although, since you are now evaluating each term separately,rather than having each of those terms in a single regex pattern and selecting the first one, it will now return the first result from each match, rather than the first one from the sequence of matched items. That may or may not be what you want.
If you want the first item from the sequence of matched items, you could do something like this:
<!--Create a variable and assign a sequence of matched items -->
<xsl:variable name="matchedMetaSequence" as="node()*">
<!--Iterate over the sequence of names that we want to match on -->
<xsl:for-each select="tokenize($csvString,',')">
<!--Build the sequence(list) of matched items,
snagging the first one that matches each value -->
<xsl:sequence select="$di:meta[matches(#domain
,concat('.*('
,current()
,').*')
,'i')][1]" />
</xsl:for-each>
</xsl:variable>
<!--Return the first item in the sequence from matching on
the list of domain regex fragments -->
<xsl:value-of select="$matchedMetaSequence[1]" />
You could also put this into a custom function like this:
<xsl:function name="di:findMeta">
<xsl:param name="meta" as="element()*" />
<xsl:param name="names" as="xs:string" />
<xsl:for-each select="tokenize(normalize-space($names),',')">
<xsl:sequence select="$meta[matches(#domain
,concat('.*('
,current()
,').*')
,'i')][1]" />
</xsl:for-each>
</xsl:function>
and then use it like this:
<xsl:value-of select="di:findMeta($di:meta,'foo,bar,baz')[1]"/>

Ruby-on-Rails: Mixing Sanitize and Truncate can be a dirty thing

So stand alone I get what I need. But I want to truncate it, my dynamic text comes out with dirty text globbered with Microsoft Word garbage.
An Example :
&Lt;! [If Gte Mso 9]>&Lt;Xml> &Lt;Br /> &Lt;O:Office Document Settings> &Lt;Br /> &Lt;O:Allow Png/> &Lt;Br /> &Lt;/O:Off...
So how do I get the best of both worlds? Is there a shorthand ruby way to do this? For example a gsub statement that would clip off everything after the 125th char?
if you just want to slice, you can
>> long_ugly_string = "omg this is a long string"
=> "omg this is a long string"
>> long_ugly_string[10..-1]
=> "s a long string"
Reference: http://ruby-doc.org/core/classes/String.html#M000771
so, you are just specifying the starting character (10) and the ending character (-1 tells it to go to the end of the string).

Resources