JSP dropdown, shortening results - database

So im trying to populate a dropdown with entries from a specific database. Right nwo it works, however it puts in the ENTIRE entry which has 10+ attributes, where i only need a couple of them. Is there any way to specify which columns get passed back and displayed in the dropdown?
<tr>
<TD><span class="required">*</span> CMS Group ID:</TD>
<td><form:select path="cmsGroupId">
<form:options items="${list}" itemValue="id" />
</form:select>
</td>
<td><form:errors path="cmsGroupId" cssClass="required" /></td>
</tr>
Ideally id like to only get the first 4 columns from here. (ID, Version, Name, Entity ID) but dont really know how to make it work. Ive found bits on doing a c:foreach loop but havent gotten that working right either...
Thanks!

Build the appropriate display values on the Java side, not in JSP.
Don't try to do this in the view layer–IMO it's not the right place for such logic.

Related

How do models work in CakePHP 3?

Recently I was given a work on a project that is being made in CakePHP 3. The project has some basic function working already and I was asked to create some new functionalities.
My understanding of PHP and MVC comes from CodeIgniter, where I have used Active Record to work with the database.
In CI, the Model was just Model. Here in Cake, I see an Entity, Table and Behavior. I somehow understood this (for me) new concept by asking around my colleagues. Now I just want to finish my assignment without asking them anything further.
So, it is a project management portal. As an Admin, you log in and you manage projects. People then come and join the project.
There are two tables I need to use:
users Table with info such as firstname, lastname, phone, address etc.
users_projects Table that stores user_id and report_id [they are Foreign Keys to users Table and reports Table respectively]
My task is to create a page where you can see who has joined in a particular project in a paginated table fashion with info from Users table such as name, surname, phone, etc..
I have prepared a new Controller called ReportsController in which I have created new participants method, so when you visit /admin/reports/participants/$project_id, it gives you the table with users joined in particular project.
ReportsController
public function participants($project_id = null)
{
$this->loadModel('Projects');
$participants = $this->Projects->selectAllProjectParticipantsByID($project_id);
foreach ($participants as $participant){
echo $participant->users[0]->firstname;
//dump($participant);
}
//dump($participants);
}
ProjectsTable
public function selectAllProjectParticipantsByID($project_id){
// return $this->find()->where(['project_id' => $project_id]);
// return $this->find()->where(['project_id' => $project_id]);
return $this->find('all')->contain([$project_id]);
}
Reports/participants template
<div class="col-xs-9">
<h3><?= __('Participants Report for') ?>
<small><?= __('Participants Report') ?></small>
</h3>
<table class="table table-bordered" cellpadding="0" cellspacing="0">
<thead>
<thead>
<tr>
<!-- <th colspan="2">--><?//= $this->Paginator->sort('id') ?><!--</th>-->
<th><?= $this->Paginator->sort('firstname', __('First Name')) ?></th>
<th><?= $this->Paginator->sort('lastname', __('Last Name')) ?></th>
<th><?= $this->Paginator->sort('phone', __('Phone')) ?></th>
<th><?= $this->Paginator->sort('address', __('Address')) ?></th>
<th><?= $this->Paginator->sort('personType', __('Person Type')) ?></th>
<th><?= $this->Paginator->sort('status', __('Status')) ?></th>
<th class="actions text-right"><?= __('More Info') ?></th>
</tr>
</thead>
<tbody class="sortable" data-url="<?= $this->Url->build(['controller' => 'QuestionSets', 'action' => 'reorder']) ?>">
</tbody>
</table>
<ul class="pagination">
</ul>
The result I get so far is following:
Error PrintScreen png
Now I have been reading about CakePHP's Pagination, Data Model, Templating etc for 16 hours now but I still am unable to get the results, which is really frustrating since I know I would have done this in another framework in a matter of minutes.
I best learn by example, sometimes I get lost by reading all the techy words in documentations, so you helping me is the best way you can teach me something.
Well, this question looks like little broad but still I want to point out following things:
Codeigniter vs CakePHP
Just as you mentioned as CakePHP covers many things/features,learning curve of cakephp is not as easy as CodeIgniter. And I would say you need to spend little more time for CakePHP documentation (CakePHP Cookbook).
One of the key advantages of CakePHP is that it provides ready to use templates. When you start to understand CakePHP relations and conventions, you will certainly feel more comfortable.
And I bet when you understand things, you can do much things with CakePHP than you do with CodeIgniter in easier fashion.
Where to start ?
Have you ever done CakePHP blog tutorials? If not this is the best place to start CakePHP. When you finished you will get basics things in CakePHP well. If you escape these basics things it would be hard to understand cakephp conventions,relations and MVC. See here (Cakephp3 blog tutorial.)
The things you did in CodeIgniter model,is basically done with table objects (eg.UsersTable.php) in CakePHP. These objects provide access to collections of data. They allow you to save new records, modify/delete existing ones, define relations, and perform bulk operations.
Talking about the error:
You need to know about what is contain and what to contain:
$this->find('all')->contain([$project_id]);
You need to contain tables (like Users) not the any field of tables as you did above. Again you will understand these things when you complete blog tutorial and which is pretty straightforward.

Date greater than the current time in Angular

I'm having to move a project from rails to angular, Much to my disgrace.
How would i go about changing this
<% if souporder.datefrom > Time.now %>
into angular terms?
heres my code
<tr ng-repeat="soup in souporders">
<td>{{soup.id}}</td>
<td>{{soup.soup}}</td>
<td>{{soup.datefrom}}</td>
<td>{{soup.dateto}}</td>
</tr>
Edit
This is in my view
<div ng-repeat="soup in souporders">
<tr ng-if="date == soup.datefrom">
And this is in my controller
$scope.date = new Date();
You clarified in the comments that you only need this calculated on page refresh, which is pretty simple and doesn't require much angular magic.
On initializing the view's controller, simply set a variable whether or not the order date is in the future or not and expose it on the scope. Then bind directly to it, and use the bindonce functionality {{:myvariable}} to improve performance because it won't be changing anyway.
Depending on your needs, you can even have the server calculate that value and return it as a property of each order in your JSON array of orders. (I'm guessing a bit at what you're doing, but you can adapt the answer if you're not doing what I think you're doing.)
Update: I just realized that perhaps your objective is not to do something special with each row based on the date, but to filter the list based on the date. Most of my answer still stands, but you can forget about the bindonce spiel. What you need is called an angular filter on ng-repeat and is done using the pipe (|) character. You can read all about it by searching the topic. There are examples in the angularjs docs. But basically, instead of:
<tr ng-repeat="soup in souporders">
<td>{{soup.id}}</td>
<td>{{soup.soup}}</td>
<td>{{soup.datefrom}}</td>
<td>{{soup.dateto}}</td>
<td>{{:soup.active}}</> <!--do something nice here instead of just displaying true/false --->
</tr>
You might want:
<tr ng-repeat="soup in souporders | filter:{current: true}">
...etc
</tr>
Either on the server or on the client, when you load the data from the server, you can add a boolean property to the items in the souporders array that says whether it's current or not.
What this accomplishes:
You have a filtered list of items based on a property that does NOT change dynamically and requires a page reload to update. But it's fast (but not the fastest it could be if you really need to go crazy - don't prematurely optimize, you'll know what to do when the time comes to do it, and that time isn't now).
Why it's not that great:
It isn't dynamic and it isn't angular-y or declarative. But based on your requirements, it's a solution. I'd spend some time considering if you want this to be dynamic, and if not, why the items that aren't showing are even returned from the server. Are they used elsewhere on the page?

Angular - Table with dynamic rows without ng-repeat?

I have an app I am working to re-create in angular. One section is a list of items that currently has 140 different items. Each item has a table with 1-4 rows, and differing numbers of columns (usually 6-20).
The way the information works, we really need to show all the items to start. However, the processing time to render the tables using ng-repeat, as well as the massively exponential number of scopes is prohibitive, especially since some users will have older computers (although likely running FF or Chrome, so I'm not worried about IE issues).
I have all the data locally in a json array, and I can format it as needed. Of course, there is filtering, so things will be shown/hidden all over. But the data in the tables is one time bound, and doesn't change.
I'd really prefer to make this something that is in a template. I could either loop it in a javascript array, or create the table data myself that way. However, in angular, templates are not allowed to have logic, so I can't do that.
I'd prefer to do everything rendering client side for speed, so I'd prefer not to have to call up the server to render it.
I could also pre-render it in the json, and use sanitize I believe, but that seems back door and against the separation of interests which is core to angular.
What would be the best practices in this case? I think I've tried about everything, and nothing within angular seems perfomant enough for this case. I'd prefer not to have to use paging, since the users would want to scroll multiple filtered long lists. Any suggestions?
Edit: Now with some sample code:
<table id="{{::item.name}}}" class="table table-striped table-bordered table-hover table-condensed table-responsive text-center" >
<thead>
<tr>
<td ng-repeat="header in ::item.tableHeader">{{::header}}</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="diff in ::item.tableInfo track by $index">
<td ng-repeat="cell in ::diff track by $index">{{::cell}}</td>
</tr>
</tbody>
</table>
I used arrays because the order matters, and objects don't always follow the order. Again, with over 140 items, 1-4 rows with 10-20 columns, the scopes become quite costly.

angular-js + tr-ng-grid - how to change the displayed table's schema?

I have a simple Angular-JS page that uses tr-ng-grid tag
<div ng-controller="TableDataCtrl">
<div id="tableview_element">
<table tr-ng-grid="" items="data"
ng-show="data_available()">
</table>
</div>
{{str_data}}
</div>
Whenever user clicks on a link, the application should display a different table. The controller is able to obtain the JSON data from the server using HTML get. 'str_data' is stringified form of the JSON data. That seems correct always.
But the tr-ng-grid does not ever update the table's schema. It seems to lock on to the very first table that is displayed with it. The whole table may be hidden or displayed using ng-show(), but then the column headings don't get modified to that of the newly loaded table.
To be very clear: Say you have two tables, birds and mammals. If the first table is a list of all birds and birds-attributes, tr-ng-grid displays the table by automatically figuring out the column headings. If the user clicks on mammals then on the page, the mammal data gets loaded, but tr-ng-grid is still looking for bird-attributes in a mammals table which has a different set of columns (and a few common columns like id and name)
How would one force tr-ng-grid to erase the current template and construct a whole new table?
One method is of course to keep every table in its own controller, and own HTML element. Is there a simpler way? or is there an alternative to tr-ng-grid that supports such a full-fledged table view refresh?
Seems like, grid headers are initialized only once.
One solution to solve your problem is to re-compile the grid whenever the data is changed.
Here is the updated plunker. http://plnkr.co/edit/34nUGmopB8q4GWQ9uF57?p=preview

Classic ASP Update table with dynamic Checkbox values

I have two tables:
1) Holds a list of propertyTypes
2) Holds the propertyDetails
The user views the page and the list of propertyTypes are shown on screen - these are checkboxes that are pulled from propertyTypes and I have a repeat region around them to display them all.
The user can select a number of these propertyTypes and I want to be able to update the propertyDetails table with that information.
I have a varchar(max) field and want the data to go into there separated by commas. It may not be the best way, but the way we have opted for.
My issue, is how do I store the relevant ID's for each checkbox in that fields using Classic ASP?
I have bound the checkbox as follows so far, but it doesn't seem to work:
<input type="checkbox" name="propertyType" id="<%=(rsPropTypes.Fields.Item("ptID").Value)%>">
Any advice would be appreciated.
Thanks
Nick
try this.
myvalue=rsPropTypes.Fields.Item("ptID").Value
<input type="checkbox" name="propertyType" id="<%response.write(myvalue)%>">

Resources