Well we're trying to render a shitload of lists. Some of them have only one entry and we want them to appear as read only input fields (so users don't get fooled and it's easier to read).
But it seems kinda hard to access the inner selectitems size from outside.
I had my go with overwriting the htmlselectonemenu tag... Is there a different nicer way? Even possible to access it on tag level?
/**
* In case there is only one or less elements in the select list -> set readonly(true)
*/
public class HtmlSelectOneMenuModf extends HtmlSelectOneMenu {
#Override
public boolean isReadonly() {
for (Iterator iterator = getChildren().iterator(); iterator.hasNext();) {
Object obj = iterator.next();
if ( obj instanceof UISelectItems) {
UISelectItemsi = (UISelectItems) obj;
if(i.getSelectItems().size() <=1)
super.setReadonly(true);
}
}
return super.isReadonly();
}
}
We're chilling on JSF 1.2 btw...
Use JSTL fn:length().
<%#taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
...
<h:selectOneMenu value="#{bean.item}" readonly="#{fn:length(bean.items) le 1}">
<f:selectItems value="#{bean.items}" />
</h:selectOneMenu>
Related
I'm new to thymeleaf and I'm trying to create a web component. What I want is something as this:
<components:panel><div>hi!</div></components:panel>
translated to something like this:
<div class="panel"><div class="contents"><div>hi!</div></div></div>
I've been trying to extend an AbstractElementTagProcessor, but I can't seem to figure out how to get the tags inside the processed tag:
public class PanelTagProcessor extends AbstractElementTagProcessor {
private static final String ELEMENT_NAME = "panel";
private static final int PRECEDENCE = 10000;
public PanelTagProcessor(final String dialectPrefix) {
super(TemplateMode.HTML, "components", ELEMENT_NAME, true, null, false, PRECEDENCE);
}
#Override
protected void doProcess(ITemplateContext context, IProcessableElementTag tag,
IElementTagStructureHandler structureHandler) {
// How could I surround contents inside the tag with custom nodes?
}
}
I'd be grateful if someone could help me :)
Regards
Luis
First, I don't think it's possible to do with just a AbstractElementTagProcessor. According to the documentation, those kind of processors "execute on open/standalone tag events only (no processors can be applied to close tags), and have no (direct) access to the element body."
I managed to get it working which an AbstractElementModelProcessor ("execute on complete elements, including their bodies, in the form of IModel objects"), so here is what worked for me.
public class PanelTagProcessor extends AbstractElementModelProcessor {
private static final String TAG_NAME = "panel";
private static final int PRECEDENCE = 10000;
public PanelTagProcessor(String dialectPrefix) {
super(TemplateMode.HTML, dialectPrefix, TAG_NAME, true, null, false, PRECEDENCE);
}
#Override
protected void doProcess(ITemplateContext itc, IModel imodel, IElementModelStructureHandler iemsh) {
IModelFactory modelFactory = itc.getModelFactory();
imodel.replace(0, modelFactory.createOpenElementTag("div", "class", "panel"));
imodel.insert(1, modelFactory.createOpenElementTag("div", "class", "contents"));
imodel.insert(imodel.size() - 2, modelFactory.createCloseElementTag("div"));
imodel.replace(imodel.size() - 1, modelFactory.createCloseElementTag("div"));
}
}
I'm using stof/StofDoctrineExtensionsBundle (Bundle wrapper for Atlantic18/DoctrineExtensions) to implement a Nested Set (tree) entity. The entity is configured and working, but I can't figure out how to retrieve all root notes with all of their children (full trees) in a single query. I currently have the full collection returning however it lazy loads all children, meaning a large number of queries is performed.
Thanks for any help.
You can just use childrenHierarchy() method for whole tree retrieve:
$tree = $repo->childrenHierarchy();
Found a solution.
retrieve full list of node objects:
$repo = $this->getDoctrine()->getManager()->getRepository('NestedEntity');
$nodes = $repo->getChildren();
build tree with your nodes.
$tree = $repo->getRepoUtils()->buildTreeArray($nodes);
buildTreeArray method accepts array of node-arrays, so you must implement ArrayAccess interface in your Entity. Also it puts all children in __children key of node-array.
/**
* #Gedmo\Tree(type="nested")
* #ORM\Table(name="nested_entity")
* #ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository")
*/
class NestedEntity implements \ArrayAccess
{
public function offsetExists($offset)
{
return property_exists($this, $offset);
}
public function &offsetGet($offset)
{
return $this->$offset;
}
public function offsetSet($offset, $value)
{
$this->$offset = $value;
}
public function offsetUnset($offset)
{
$this->$offset = null;
}
protected $__children = [];
...
I use Joomla 2.5 framework.
I have simple table such as:
int id
string itemid
Now I just want to load all 'itemid's to array using JTable. Is here possibility?
Everything about the JTable Class only deals with one row, as soon as multiple rows are involved, you have two options:
1) Use the solution you gave.
2) Override the load() function in your Table class. This can be done as under:
Put the following load() function in your Table class:
function load($key = null)
{
$db = $this->getDBO();
$query = $db->getQuery(true);
$query->select($key);
$query->from($this->getTableName());
$db->setQuery($query);
$row = $db->loadRowList();
if ($db->getErrorNum())
{
$this->setError($db->getErrorMsg());
return false;
}
// Check that we have a result.
if (empty($row))
{
return false;
}
//Return the array
return $row;
}
Now call the load() function with a single argument 'itemid', and get the array you want.
This worked for me, hope it helps you too.
Solution that I decided to use is inherit model class from JModelList:
class modelModelcomponent extends JModelList
{
protected function getListQuery()
{
// Create a new query object.
$db = JFactory::getDBO();
$query = $db->getQuery(true);
// Select some fields
$query->select('itemid');
// From the hello table
$query->from('#__table');
return $query;
}
}
I'm trying to get an attribute for it to be listed on list.phtml, the form that is being made is as follows:
I created a module on the Block and created a function which captures the attribute:
protected function getPreOrder()
{
$productId = $this->getRequest()->getParam('id');
$product = Mage::getModel('catalog/product')->load($productId);
$preOrder = $product->getNewsFromDate();
$preOrder = substr($preOrder, 0, 10);
return $preOrder;
}
public function getViewList()
{
if(strtotime(date('Y-m-d')) <= strtotime($this->getPreOrder()))
{
return true;
} else {
return false;
}
}
However, nothing is returned. I also did this same method to view.phtml and it worked perfectly. That goes for a file before the function getChildHtml() phtml, is not being edited list.phtml
That makes sense to create a loop, but the loop is already list.phtml!
What would be the way?
I thank you.
Have you debugged your block function to see if the product id is correct and if its loading the model correctly ??
Also debug the template list.phtml to check if its correctly loading the block type ?
get_class($this);
and see what class type is it.
I have written an ASP.NET web service.
It looks like this:
WebServices.logic pLogic = new WebServices.logic();
WebServices.manager[] pManager = new PowerManager[1];
pManager[0] = new PowerManager();
pManager[0].CustomerId = "sjsjshd";
pManager[0].state = pLogic.getState("sasj");
return pManager[0];
The pManager class looks like this:
public string _CustomerId;
public int PowerStatus;
public List<ArrayList> _Power;
public string CustomerId
{
get
{
return _CustomerId;
}
set
{
_CustomerId = value;
}
}
public List<ArrayList> Power
{
get
{
return _Power;
}
set
{
_Power = value;
}
}
When I run it, I get a repetition of the results, like so:
<p>
<_CustomerId>sjsjshd</_CustomerId>
<pStatus>0</PowerStatus>
−
<_p>
−
<ArrayOfAnyType>
<anyType xsi:type="xsd:int">1</anyType>
</ArrayOfAnyType>
<ArrayOfAnyType/>
</_p>
<CustomerId>sjsjshd</CustomerId>
−
<p>
−
<ArrayOfAnyType>
<anyType xsi:type="xsd:int">1</anyType>
</ArrayOfAnyType>
<ArrayOfAnyType/>
</p>
</pManager>
However, there is no duplicate values stored (Eg. I store client name in a collection, but only once - count of 1). There are no duplicates stored when I call getState(). This method returns a collection and it contains one value, but the results in XML has a repetition of this.
How comes the results appear to repeat themselves? When running the system, I only get one error.
Thanks
OK, looks like your XML serialization is giving you all the public members of your PowerManager class. Based on the naming convention of starting with an underscore, those members should be private, like this:
private string _CustomerId;
private List<ArrayList> _Power;
You also state "When running the system, I only get one error." What error are you getting?